package com.zyx.concurrentdemo.mytest.c03;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author Yaxi.Zhang
 * @since 2021/10/12 13:05
 */
@Slf4j(topic = "c.InterrputDemo")
public class InterrputDemo {
    public static void main(String[] args) {
        Thread t1 = new Thread("t1") {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    log.debug("wakeup");
                    log.error("error: ", e);
                    log.debug("thread state: {}", Thread.currentThread().getState());
                }
            }
        };
        log.debug("thread state: {}", t1.getState());
        t1.start();

        try {
            TimeUnit.MILLISECONDS.sleep(500L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.debug("interrupt...");
        t1.interrupt();

        log.debug("thread state: {}", t1.getState());

        try {
            TimeUnit.MILLISECONDS.sleep(3000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        log.debug("thread state: {}", t1.getState());
    }

}
